/*******************************************************************************
 * Copyright (c) 2009-2011 ETCORE Labs. All rights reserved. 
 * 
 * This software is the confidential and proprietary information of ETCORE Labs.
 * You shall not disclose such confidential information and shall use it
 * only in accordance with the terms of the license agreement you entered into
 * with ETCORE Labs. 
 * 
 * Support can be obtained from support forums at:  http://www.etcore.com/
 * /
 *******************************************************************************/
package etcore.webapp.grouptalk.common.service;

import java.util.List;

import org.hibernate.Session;

import etcore.webapp.grouptalk.common.dao.GroupRelationshipDAO;
import etcore.webapp.grouptalk.common.dao.HibernateSessionFactory;
import etcore.webapp.grouptalk.common.object.GroupRelationship;

/**
 * GroupRelationshipService implements queries and transactions on
 * GroupRelationship
 * 
 * @author ETCORE GroupTalk Developers
 * 
 */
public class GroupRelationshipService extends BaseService {
	public List<GroupRelationship> findByProperty(String propertyName,
			Object value, int begin, int length) {
		Session session = HibernateSessionFactory.getSession();
		try {
			GroupRelationshipDAO dao = new GroupRelationshipDAO();
			List<GroupRelationship> result = dao.findByProperty(propertyName,
					value, begin, length);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public boolean exists(int gid1, int gid2) {
		Session session = HibernateSessionFactory.getSession();
		try {
			GroupRelationshipDAO dao = new GroupRelationshipDAO();
			boolean result = dao.exists(gid1, gid2);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public List<GroupRelationship> findByProperty(String propertyName,
			Object value) {
		Session session = HibernateSessionFactory.getSession();
		try {
			GroupRelationshipDAO dao = new GroupRelationshipDAO();
			List<GroupRelationship> result = dao.findByProperty(propertyName,
					value);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public List<GroupRelationship> findBy2Properties(String propertyName,
			Object value, String propertyName2, Object value2, int begin,
			int length) {
		Session session = HibernateSessionFactory.getSession();
		try {
			GroupRelationshipDAO dao = new GroupRelationshipDAO();
			List<GroupRelationship> result = dao.findBy2Properties(
					propertyName, value, propertyName2, value2, begin, length);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public long findSizeByProperty(String propertyName, Object value) {

		Session session = HibernateSessionFactory.getSession();
		try {
			GroupRelationshipDAO dao = new GroupRelationshipDAO();
			long result = dao.findSizeByProperty(propertyName, value);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public List<GroupRelationship> findBy2Property(String propertyName1,
			Object value1, String propertyName2, Object value2) {
		Session session = HibernateSessionFactory.getSession();
		try {
			GroupRelationshipDAO dao = new GroupRelationshipDAO();
			List<GroupRelationship> result = dao.findBy2Property(propertyName1,
					value1, propertyName2, value2);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public List<GroupRelationship> findAll(int begin, int length) {
		Session session = HibernateSessionFactory.getSession();
		try {
			GroupRelationshipDAO dao = new GroupRelationshipDAO();
			List<GroupRelationship> result = dao.findAll(begin, length);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

}